#include <vector>
using namespace std;
class Solution
{
public:
    int findPoisonedDuration(vector<int> &timeSeries, int duration)
    {
        int time = 0;
        int start = 0, end = 0;
        for (auto e : timeSeries)
        {
            if (e > end)
            {
                time += end - start;
                start = e;
            }
            end = e + duration;
        }
        time += end - start;
        return time;
    }
};